//
//  JYBaseOrderController.m
//  JYFarm
//
//  Created by 花花 on 2017/10/16.
//  Copyright © 2017年 花花. All rights reserved.
//

#import "JYBaseOrderController.h"
#import "JYOrderCell.h"
#import "JYOrderModel.h"
#import "JYOrderDetaController.h"

@interface JYBaseOrderController ()
@property(nonatomic)NSMutableArray *dataArr;


@end

static NSString *JYOrderCellID = @"JYOrderCellID";
@implementation JYBaseOrderController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setupTableView];

}
- (void)setType:(JYOrderType)type{

    _type = type;
    
    [self.tableView reloadData];

}
- (void)setupTableView{
    
    
    self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 40, 0);
    self.tableView.scrollIndicatorInsets = self.tableView.contentInset;
    self.tableView.rowHeight = 258;
    [self.tableView registerNib:[UINib nibWithNibName:@"JYOrderCell" bundle:nil] forCellReuseIdentifier:JYOrderCellID];
    
    
}
/*
 JYOrderType_all = 0, // 全部
 JYOrderType_pay = 1,//待付款
 JYOrderType_shipping = 2,//待发货
 JYOrderType_goods = 3,//待收货
 JYOrderType_complete = 4,//已完成
 */
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    if (_type == JYOrderType_all) {
        return 1;
    }else if (_type == JYOrderType_pay){
      return 2;
    }else if (_type ==JYOrderType_shipping){
     return 3;
    }else if (_type == JYOrderType_goods){
    
        return 4;
    }else{
    return 5;
    
    }
    
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    JYOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:JYOrderCellID];
    cell.orderNumberLabel.text = [NSString stringWithFormat:@"订单号%zd",arc4random_uniform(666888123)];
    cell.totalLabel.text = [NSString stringWithFormat:@"共%zd件商品",arc4random_uniform(100)];
    
    NSString * momey  =  [NSString stringWithFormat:@"￥%zd.00",arc4random_uniform(100)];
    //@"￥10.00";
//    NSString *yjStr = @"（含押金￥50元）";
    NSString *yjStr =  [NSString stringWithFormat:@"（含押金￥%zd元）",arc4random_uniform(99)];

    ;
    NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc]initWithString:momey];
    NSDictionary *attributes = @{
                                 NSFontAttributeName:kFont(13),
                                 NSForegroundColorAttributeName:k9Color
                                 };
    NSAttributedString *str = [[NSAttributedString alloc]initWithString:yjStr attributes:attributes];
    [attributedStr appendAttributedString:str];
    cell.moneyLabel.attributedText = attributedStr;
    
    cell.collectionView.orderDataArr = @[@"全部",@"待付款",@"待发货",@"待收货",@"已完成",@"全部",@"待付款",@"待发货",@"待收货",@"已完成",@"全部",@"待付款",@"待发货",@"待收货",@"已完成"];
    return cell;
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    [tableView deselectRowAtIndexPath:indexPath animated:YES];
        JYOrderDetaController *detaVc = [JYOrderDetaController new];
           detaVc.type = _type;
            [self.navigationController pushViewController:detaVc animated:YES];
        

}
- (NSMutableArray *)dataArr{

    if (!_dataArr) {
        _dataArr = [NSMutableArray array];
    }
    return _dataArr;

}





@end
